package com.firstpro.web;

import com.firstpro.domain.UserEntity;
import com.firstpro.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


/**
 * Created by zhl on 2017/6/27.
 */
@Controller
@RequestMapping("/user")
public class usercontroller {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(value = "createUser",method = RequestMethod.POST)
    public ModelAndView regist(UserEntity user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("registSuccess");
        try {
            userService.creatUser(user);
            modelAndView.addObject("userName",user.getUserName());
        }catch (Exception e) {
            modelAndView.setViewName("createFailed");
        }
        return modelAndView;
    }

}
